package com.clss.webrtclibrary;

import org.webrtc.PeerConnection;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liuv
 * 配置和工具类
 */
public class ConfigAndUtils {
    private static final String TAG = "ConfigAndUtils";

    public static final String VIDEO_TYPE_GROUP_CALL = "groupcall";
    public static final String VIDEO_TYPE_PLAYER = "player";

    /**
     * 从官方demo照搬过来的
     */
    public static final String VIDEO_TRACK_ID = "ARDAMSv0";
    public static final String AUDIO_TRACK_ID = "ARDAMSa0";
    public static final String VIDEO_TRACK_TYPE = "video";
    public static final String VIDEO_CODEC_VP8 = "VP8";
    public static final String VIDEO_CODEC_VP9 = "VP9";
    public static final String VIDEO_CODEC_H264 = "H264";
    public static final String VIDEO_CODEC_H264_BASELINE = "H264 Baseline";
    public static final String VIDEO_CODEC_H264_HIGH = "H264 High";
    public static final String AUDIO_CODEC_OPUS = "opus";
    public static final String AUDIO_CODEC_ISAC = "ISAC";
    public static final String VIDEO_CODEC_PARAM_START_BITRATE = "x-google-start-bitrate";
    public static final String VIDEO_FLEXFEC_FIELDTRIAL =
            "WebRTC-FlexFEC-03-Advertised/Enabled/WebRTC-FlexFEC-03/Enabled/";
    public static final String VIDEO_VP8_INTEL_HW_ENCODER_FIELDTRIAL = "WebRTC-IntelVP8/Enabled/";
    public static final String VIDEO_H264_HIGH_PROFILE_FIELDTRIAL =
            "WebRTC-H264HighProfile/Enabled/";
    public static final String DISABLE_WEBRTC_AGC_FIELDTRIAL =
            "WebRTC-Audio-MinimizeResamplingOnMobile/Enabled/";
    public static final String AUDIO_CODEC_PARAM_BITRATE = "maxaveragebitrate";
    public static final String AUDIO_ECHO_CANCELLATION_CONSTRAINT = "googEchoCancellation";
    public static final String AUDIO_AUTO_GAIN_CONTROL_CONSTRAINT = "googAutoGainControl";
    public static final String AUDIO_HIGH_PASS_FILTER_CONSTRAINT = "googHighpassFilter";
    public static final String AUDIO_NOISE_SUPPRESSION_CONSTRAINT = "googNoiseSuppression";
    public static final String DTLS_SRTP_KEY_AGREEMENT_CONSTRAINT = "DtlsSrtpKeyAgreement";

    /**
     * 如果MediaInfoBean中没有iceServer信息，则使用默认的穿墙服务器配置信息
     */
    public static List<PeerConnection.IceServer> getIceServer(List<KurentoSignallingBean.IceServersBean> iceServerList) {
        ArrayList<PeerConnection.IceServer> iceServers = new ArrayList<>();
        for (KurentoSignallingBean.IceServersBean iceServersBean : iceServerList) {
            if (iceServersBean.getUrls().contains("stun")) {
                iceServers.add(PeerConnection.IceServer.builder(iceServersBean.getUrls()).createIceServer());
            } else {
                iceServers.add(PeerConnection.IceServer
                        .builder(iceServersBean.getUrls())
                        .setUsername(iceServersBean.getUsername())
                        .setPassword(iceServersBean.getCredential())
                        .createIceServer());
            }
        }
        return iceServers;
    }

    public static String HAVE_LOCAL_OFFER = "HAVE_LOCAL_OFFER";
    public static String STABLE = "STABLE";
    public static String CHECKING = "CHECKING";
    public static String CONNECTED = "CONNECTED";
    public static String COMPLETED = "COMPLETED";
    public static String DISCONNECTED = "DISCONNECTED";
    public static String FAILED = "FAILED";
    public static String CLOSED = "CLOSED";
}
